#define BOOLEAN int
#define TRUE 1
#define FALSE 0
#include<stdio.h>
#include<stdlib.h>

   typedef struct singly_linked_list_node
   {
        int data;
        struct singly_linked_list_node *next;
   }node;

         node *enqu(int , node*);
         void displayQueue(node*);

int main()
{
     int element,choice;
     node *first;
     first=NULL;
 
     do{
           printf("Enter a positive integer or 0 to end :\n");
           scanf("%d",&element);
           if(element>0)
           {
               first=enqueue(element,first);
           }
     }while(element<0 || element>0);
  
     printf("\nElements of queue:\n");
     displayQueue(first);

 return (1);
}

node *enqueue(int element, node *first)
{
      BOOLEAN end=FALSE;
      node *fresh, *temp;
      fresh=(node *)malloc(sizeof(node));

      if(first==NULL)
      {
          (*fresh).data=element;
          (*fresh).next=NULL;
          first=fresh;
      }
      else
      {
           temp=first;
           end=FALSE;
           while(!end)
           {
	        if((temp->next==NULL))
	        {
	             (*fresh).data=element;
	   		 (*fresh).next=(*temp).next;
	   		temp->next=fresh;
   		       end=TRUE;
	         }
	         else
	         {
	             temp=(*temp).next;
               }
           }
      }
  
   return first;
}

void displayQueue(node *first)
{
      node *temp;
      temp=first;
      if(temp==NULL)
          printf("Queue is empty");
      else
      {
          while(temp!=NULL)
          {
	         printf("%d\n",(*temp).data);
	         temp=temp->next;
          }
      }
}
